package cn.ffcs.uec.salary.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.salary.dao.UecSalaryProjectDao;
import cn.ffcs.uec.salary.model.UecSalaryProject;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecSalaryProjectDao")
@Transactional
public class UecSalaryProjectDaoImpl extends BaseDaoImpl implements UecSalaryProjectDao {

	@Override
	public PageInfo queryPageInfoByUecSalaryProject(UecSalaryProject uecSalaryProject, int current,
			int pageSize) {
		if (null != uecSalaryProject) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_SALARY_PROJECT T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			
			// 薪资项目编码
			if (!StrUtil.isNullOrEmpty(uecSalaryProject.getCode())) {
				sb.append(" AND T.CODE like ? ");
				params.add("%"+ uecSalaryProject.getCode() + "%");
			}
			
			// 薪资项目名称
			if (!StrUtil.isNullOrEmpty(uecSalaryProject.getName())) {
				sb.append(" AND T.NAME like ? ");
				params.add("%"+ uecSalaryProject.getName() + "%");
			}
			
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecSalaryProject.class);
		} else {
			return null;
		}
	}

	@Override
	public UecSalaryProject findObjectByUecSalaryProject(UecSalaryProject uecSalaryProject) {
		StringBuilder sb = new StringBuilder(
				" SELECT * FROM UEC_SALARY_PROJECT T  WHERE T.STATUS_CD = ? ");
		List<Object> params = new ArrayList<Object>();
		params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
		if(null != uecSalaryProject) {
			if(!StrUtil.isNullOrEmpty(uecSalaryProject.getPkWaItem())) {
				sb.append(" AND T.PK_WA_ITEM = ? ");
				params.add(uecSalaryProject.getPkWaItem());
			}
			List<UecSalaryProject> list = super.jdbcFindList(sb.toString(), params,
					UecSalaryProject.class);
			if (list.size()>0 && list != null) {
				return list.get(0);
			}
		}
		return null;
	}
}
